@echo off 
setlocal

if NOT DEFINED cmake_bin (
    set cmake_bin="D:\software\msvc\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe"
)

set build_type=%1

if "%build_type%" == "" (
    set build_type=Release
)


call setup.bat %build_type%

set script_dir=%~dp0
set build_dir=%script_dir%deploy
rd /S /Q %build_dir%
if not exist %build_dir% md %build_dir%

if NOT DEFINED INTEROP_BIN_ROOT (
    set INTEROP_BIN_ROOT=D:/workspace/exchange/cad/amcax_interop/deploy/install/%build_type%
)

if NOT DEFINED INTEROP_BIN (
    set INTEROP_BIN=D:/workspace/exchange/cad/amcax_interop/deploy/install/%build_type%/bin
)

if NOT DEFINED DATAKIT_BIN_ROOT (
    set DATAKIT_BIN_ROOT=D:/workspace/exchange/cad/amcaxdatakit/deploy/install/%build_type%
)

if NOT DEFINED DATAKIT_BIN (
    set DATAKIT_BIN=D:/workspace/exchange/cad/amcaxdatakit/deploy/install/%build_type%/bin
)

set PATH=%build_dir%;%INTEROP_ROOT%/win_b64/code/bin;%DATAKIT_ROOT%/win_b64/code/bin;%ACIS_ROOT%/win_b64/code/bin;%PATH% 

call %cmake_bin% -DCMAKE_BUILD_TYPE:STRING=%build_type%  -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DInterOp=on -DAMXStorage=on  --no-warn-unused-cli -S%script_dir% -B%build_dir%

call %cmake_bin%  --build %build_dir% --config %build_type%  -j20 
echo "Build done"

call %cmake_bin% --install %build_dir%  --strip --config %build_type%

set install_dir=%build_dir%\install

git log -n 3 > %install_dir%\%build_type%\git.log

set YEAR=%date:~0,4%
set MONTH=%date:~5,2%
set DAY=%date:~8,2%

:: 获取时间 (12:34:56)
set HOUR=%time:~0,2%
set MINUTE=%time:~3,2%
set SECOND=%time:~6,2%

:: 去掉前导空格
if "%HOUR:~0,1%"==" " set HOUR=0%HOUR:~1,1%

:: 拼接时间戳
set TIMESTAMP=%YEAR%%MONTH%%DAY%_%HOUR%%MINUTE%%SECOND%

set artifact_dir=%build_dir%


copy %script_dir%doc\README_InterOp.md %install_dir%\%build_type%\README.md
set artifact_path=ExchangeSDK_ENHANCE_%TIMESTAMP%.tar.xz

cd %build_dir%\install

tar -cvJf %artifact_path% %build_type%

endlocal
